package com.subsequent.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsequent.mapper.DepartmentsMapper;
import com.subsequent.mapper.HospitalsMapper;
import com.subsequent.pojo.Departments;
import com.subsequent.pojo.Doctors;
import com.subsequent.pojo.Hospitals;
import com.subsequent.service.DoctorsService;
import com.subsequent.mapper.DoctorsMapper;
import com.subsequent.utils.Result;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
* @author 申其卓
* @description 针对表【doctors(医生信息表)】的数据库操作Service实现
* @createDate 2025-05-07 16:28:34
*/
@Service
public class DoctorsServiceImpl extends ServiceImpl<DoctorsMapper, Doctors>
    implements DoctorsService{
    @Resource
    private DoctorsMapper doctorsMapper;
    @Resource
    private HospitalsMapper hospitalsMapper;
    @Resource
    private DepartmentsMapper departmentsMapper;
    @Override
    public Result findDoctorById(Integer userId) {
        if(userId!=null){
            QueryWrapper<Doctors>queryWrapper=new QueryWrapper<>();
            queryWrapper.lambda().eq(Doctors::getUserId,userId);
            Doctors doctors = doctorsMapper.selectOne(queryWrapper);
            Hospitals hospitals = hospitalsMapper.selectById(doctors.getHospitalsId());
            Departments departments = departmentsMapper.selectById(doctors.getDeptId());
            if(hospitals==null|| departments==null){
                return Result.error("未找到医生信息");
            }
            doctors.setDepartments(departments);
            doctors.setHospitals(hospitals);
            return Result.success(doctors);
        }
        return Result.error("用户ID不能为空");
    }

    @Override
    public Result updateIntroduction(Doctors doctors) {
        if(doctors!=null){
            int i = doctorsMapper.updateByIntroduction(doctors);
            if (i>0){
                return Result.success("修改成功");
            }else {
                return Result.error("修改失败");
            }
        }
        return Result.error("数据异常");
    }

    @Override
    public Result updateSpecialty(Doctors doctors) {
        if(doctors!=null){
            int i = doctorsMapper.updateBySpecialty(doctors);
            if (i>0){
                return Result.success("修改成功");
            }else {
                return Result.error("修改失败");
            }
        }
        return Result.error("数据异常");
    }
}




